import { createSlice } from '@reduxjs/toolkit'

export const counterSlice = createSlice({
    name: 'counter',
    initialState: {
        data: [],
        searchList: []
    },
    reducers: {
        getList(state, { type, payload }) {
            state.data = payload;
            state.searchList = payload;
        },















        // getList(state, { type, payload }) {
        //     state.data = payload;
        //     state.searchList = payload;
        // },
        // addData(state, { type, payload }) {
        //     state.searchList.unshift(payload);
        // },
        // delData(state, { type, payload }) {
        //     state.searchList.forEach((item, index) => {
        //         if (item.key === payload) {
        //             state.searchList.splice(index, 1);
        //         }
        //     })
        // },
        // editData(state, { type, payload }) {
        //     state.searchList.forEach((item, index) => {
        //         if (item.key === payload.key) {
        //             item.name = payload.name;
        //             item.age = payload.age;
        //             item.city = payload.city;
        //             item.phone = payload.phone;
        //             item.time = payload.time;
        //         }
        //     })
        // },
        // searchData(state, { type, payload }) {
        //     state.searchList = state.data.filter(item => item.name.includes(payload));
        // }
    }
})

export const { getList, addData, delData, editData, searchData } = counterSlice.actions

export default counterSlice.reducer